package com.cloud.bc.service.impl;

import com.cloud.bc.model.entity.BcSetmeals;
import com.cloud.bc.mapper.BcSetmealsMapper;
import com.cloud.bc.service.BcSetmealsService;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.math.BigInteger;
import java.util.List;

/**
 * 套餐配置
 *
 * @author douhaichao code generator
 * @date 2021-01-11 22:47:18
 */
@Service
@AllArgsConstructor
public class BcSetmealsServiceImpl extends ServiceImpl<BcSetmealsMapper, BcSetmeals> implements BcSetmealsService {

    /**
   * 根据对象属性查找满足条件的第一条数据     *      * @return
   */
    @Override
    public BcSetmeals selectOne(BcSetmeals req) {
        QueryWrapper queryWrapper = new QueryWrapper<BcSetmeals>();
        queryWrapper.setEntity(req);
        return baseMapper.selectOne(queryWrapper);
    }

    /**
     * 根据条件查询所有
     */
    @Override
    public List<BcSetmeals> selectAll(BcSetmeals req) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.setEntity(req);
        queryWrapper.orderByDesc("sort");
        return baseMapper.selectList(queryWrapper);
    }

    /**
     * 根据对象查询所有分页数据(精确查询)     *      * @return
     */
    @Override
    public IPage<BcSetmeals> selectPage(Page page, BcSetmeals req) {
        IPage<BcSetmeals> list = baseMapper.selectPage(
                page,
                new QueryWrapper<BcSetmeals>().setEntity(req));
        return list;
    }

    /**
     * 根据对象查询所有分页数据(模糊查询)     *      * @return
     */
    @Override
    public IPage<BcSetmeals> selectPageByLike(Page page, BcSetmeals req) {
        QueryWrapper queryWrapper = new QueryWrapper();
        
                                        if (null !=req.getId()) {
                    queryWrapper.eq("id" , req.getId());
                }
                    
                            if (!StrUtil.isEmpty(req.getName())) {
                    queryWrapper.like("name" , req.getName());
                }
                                
                            if (!StrUtil.isEmpty(req.getIcon())) {
                    queryWrapper.like("icon" , req.getIcon());
                }
                                
                                        if (null !=req.getPrice()) {
                    queryWrapper.eq("price" , req.getPrice());
                }
                    
                                        if (null !=req.getDuration()) {
                    queryWrapper.eq("duration" , req.getDuration());
                }
                    
                            if (!StrUtil.isEmpty(req.getAction())) {
                    queryWrapper.like("action" , req.getAction());
                }
                                
                            if (!StrUtil.isEmpty(req.getExplains())) {
                    queryWrapper.like("explains" , req.getExplains());
                }
                                
                                        if (null !=req.getDisplay()) {
                    queryWrapper.eq("display" , req.getDisplay());
                }
                    
                                        if (null !=req.getApply()) {
                    queryWrapper.eq("apply" , req.getApply());
                }
                    
                                        if (null !=req.getFriend()) {
                    queryWrapper.eq("friend" , req.getFriend());
                }
                    
                            if (!StrUtil.isEmpty(req.getFriendForm())) {
                    queryWrapper.like("friend_form" , req.getFriendForm());
                }
                                
                                        if (null !=req.getChat()) {
                    queryWrapper.eq("chat" , req.getChat());
                }
                    
                            if (!StrUtil.isEmpty(req.getChatForm())) {
                    queryWrapper.like("chat_form" , req.getChatForm());
                }
                                
                                        if (null !=req.getContact()) {
                    queryWrapper.eq("contact" , req.getContact());
                }
                    
                            if (!StrUtil.isEmpty(req.getContactForm())) {
                    queryWrapper.like("contact_form" , req.getContactForm());
                }
                                
                                        if (null !=req.getGreet()) {
                    queryWrapper.eq("greet" , req.getGreet());
                }
                    
                            if (!StrUtil.isEmpty(req.getGreetForm())) {
                    queryWrapper.like("greet_form" , req.getGreetForm());
                }
                                
                                        if (null !=req.getSms()) {
                    queryWrapper.eq("sms" , req.getSms());
                }
                    
                            if (!StrUtil.isEmpty(req.getSmsForm())) {
                    queryWrapper.like("sms_form" , req.getSmsForm());
                }
                                
                                        if (null !=req.getUserGroupId()) {
                    queryWrapper.eq("user_group_id" , req.getUserGroupId());
                }
                    
                                        if (null !=req.getExpireUserGroupId()) {
                    queryWrapper.eq("expire_user_group_id" , req.getExpireUserGroupId());
                }
                    
                                        if (null !=req.getSort()) {
                    queryWrapper.eq("sort" , req.getSort());
                }
                            IPage<BcSetmeals> list = baseMapper.selectPage(page, queryWrapper);
        return list;
    }

    /**
     * 根据条件统计数据量     *      * @return
     */
    @Override
    public int count(BcSetmeals req) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.setEntity(req);
        return baseMapper.selectCount(queryWrapper);
    }
}
